# SET(CUR_ARCH "aarch64")
# SET(CUR_ARCH "armhf")
SET(CUR_ARCH "x86_64")
SET(PREFIX /home/sunjie/work)
# SET(PREFIX /home/zyx/work)

SET(CMAKE_C_FLAGS "-O3 -fPIC -ldl -lpthread -lrt")
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=c++14")
#  
message("CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")


SET(UTILS_DIR ${PROJECT_SOURCE_DIR}/../base_util)
SET(STREAM_DIR ${PROJECT_SOURCE_DIR}/../stream)
SET(COMMON_DIR ${PROJECT_SOURCE_DIR}/../common)
SET(ONNXMODEL_DIR ${PROJECT_SOURCE_DIR}/onnx)

aux_source_directory(${UTILS_DIR} util_src)

SET(ONNXMODEL_SOURCE
    ${util_src}

    ${COMMON_DIR}/face_tool.cpp

    ${STREAM_DIR}/osd_text.cpp

    ${ONNXMODEL_DIR}/../common/processor.cpp
    ${ONNXMODEL_DIR}/../common/transforms.cpp
    ${ONNXMODEL_DIR}/../common/visualize.cpp

    ${ONNXMODEL_DIR}/../base_predictor.cpp
    ${ONNXMODEL_DIR}/../model_manager.cpp
    ${ONNXMODEL_DIR}/../infer_demo.cpp
    ${ONNXMODEL_DIR}/base/onnx_predictor.cpp
    ${ONNXMODEL_DIR}/cls/cls_video.cpp
    ${ONNXMODEL_DIR}/det/det_predictor.cpp
    ${ONNXMODEL_DIR}/ocr/rec_predictor.cpp
    ${ONNXMODEL_DIR}/onnxmodel_manager.cpp
    main.onnx.cpp

)

set(TARGET_NAME model.onnx)
add_executable(${TARGET_NAME} ${ONNXMODEL_SOURCE})

include_directories(${PROJECT_SOURCE_DIR})
include_directories(${PROJECT_SOURCE_DIR}/../)
include_directories(${UTIL_DIR})


# ffmpeg
SET(FFMPEG_PATH ${PREFIX}/lib/ffmpeg_build.cuda.${CUR_ARCH})
set(FFMPEG_LIB
    ${FFMPEG_PATH}/lib/libavcodec.so.58
    ${FFMPEG_PATH}/lib/libavfilter.so.7
    ${FFMPEG_PATH}/lib/libavformat.so.58
    ${FFMPEG_PATH}/lib/libavutil.so.56
    ${FFMPEG_PATH}/lib/libswresample.so.3
    ${FFMPEG_PATH}/lib/libswscale.so.5
)
include_directories(${FFMPEG_PATH}/include)
target_link_libraries(${TARGET_NAME} ${FFMPEG_LIB})


# opencv
SET(OPENCV_PATH ${PREFIX}/lib/opencv-4.5.2/install.ffmpeg.cuda.${CUR_ARCH})
set(OPENCV_LIB ${OPENCV_PATH}/lib/libopencv_world.so.4.5)
include_directories(${OPENCV_PATH}/include/opencv4)
target_link_libraries(${TARGET_NAME} ${OPENCV_LIB})

# freetype
SET(FREE_PATH ${PREFIX}/lib/freetype-2.13.2/install.${CUR_ARCH})
set(FREE_LIB ${FREE_PATH}/lib/libfreetype.so.6.20.1)
include_directories(${FREE_PATH}/include/freetype2)
target_link_libraries(${TARGET_NAME} ${FREE_LIB})

#harfbuzz
SET(HARF_PATH ${PREFIX}/lib/harfbuzz-7.2.0/install.${CUR_ARCH})
set(HARF_LIB ${HARF_PATH}/lib/libharfbuzz.so.0.60720.0)
include_directories(${HARF_PATH}/include/harfbuzz)
target_link_libraries(${TARGET_NAME} ${HARF_LIB})

# onnxruntime
SET(ONNX_PATH ${PREFIX}/lib/onnxruntime-1.16.1/install.${CUR_ARCH})
set(ONNX_LIB
    ${ONNX_PATH}/lib/libonnxruntime.so
    ${ONNX_PATH}/lib/libonnxruntime_providers_tensorrt.so
    ${ONNX_PATH}/lib/libonnxruntime_providers_shared.so
    ${ONNX_PATH}/lib/libonnxruntime_providers_cuda.so
)
include_directories(${ONNX_PATH}/include)
target_link_libraries(${TARGET_NAME} ${ONNX_LIB})

# openssl
SET(OPENSSL_PATH "${PREFIX}/lib/openssl-1.1.1q/install.${CUR_ARCH}")
set(OPENSSL_LIB
    ${OPENSSL_PATH}/lib/libcrypto.so.1.1
    ${OPENSSL_PATH}/lib/libssl.so.1.1
)
include_directories(${OPENSSL_PATH}/include)
target_link_libraries(${TARGET_NAME} ${OPENSSL_LIB})

# boost
SET(BOOST_PATH "${PREFIX}/lib/boost_1_67_0")
set(BOOST_LIB
    ${BOOST_PATH}/stage/lib.${CUR_ARCH}/libboost_filesystem.a
    ${BOOST_PATH}/stage/lib.${CUR_ARCH}/libboost_system.a
    ${BOOST_PATH}/stage/lib.${CUR_ARCH}/libboost_date_time.a
    ${BOOST_PATH}/stage/lib.${CUR_ARCH}/libboost_regex.a
)
include_directories(${BOOST_PATH})
target_link_libraries(${TARGET_NAME} ${BOOST_LIB})


# json
SET(JSONCPP_PATH ${PREFIX}/lib/jsoncpp-1.9.5/install.${CUR_ARCH})
set(JSONCPP_LIB ${JSONCPP_PATH}/lib/libjsoncpp.a)
include_directories(${JSONCPP_PATH}/include)
target_link_libraries(${TARGET_NAME} ${JSONCPP_LIB})

# spdlog
SET(SPDLOG_PATH ${PREFIX}/lib/spdlog-1.9.2/install.${CUR_ARCH})
set(SPDLOG_LIB ${SPDLOG_PATH}/lib/libspdlog.a)
include_directories(${SPDLOG_PATH}/include)
target_link_libraries(${TARGET_NAME} ${SPDLOG_LIB})

# yaml
SET(YAML_PATH ${PREFIX}/lib/yaml-cpp-yaml-cpp-0.6.2/install.${CUR_ARCH})
set(YAML_LIB ${YAML_PATH}/lib/libyaml-cpp.a)
include_directories(${YAML_PATH}/include)
target_link_libraries(${TARGET_NAME} ${YAML_LIB})

target_link_libraries(${TARGET_NAME} ${CMAKE_CXX_FLAGS})
